﻿/*=================================================================
* 版权信息：Copyright (C) 2005-2011 捷点科技 All Rights Reserved.
* 文件名称：CNVP_AdminRoleMenu.cs
* 创建标识：曾乃强 15158756652 2011-04-11 09:04:55
* 修改标识：
* 功能描述：
===================================================================*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using CNVP.Framework.Helper;
using CNVP.Config;

namespace CNVP.JShop.DAL
{
    /// <summary>
    /// 对*CNVP_AdminRoleMenu*操作数据库(针对SQL Server)的实现
    /// </summary>
    public class CNVP_AdminRoleMenu
    {
       private string Prefix = DBConfig.Prefix;
        #region DAL
        /// <summary>
        /// 添加
        /// </summary>
        public int Insert(Model.CNVP_AdminRoleMenu obj)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("insert into  " + Prefix + "AdminRoleMenu ([MenuID],[AdminRoleID])");
            sql.Append("values(@MenuID,@AdminRoleID)");
            
            SqlParameter[] pra = {
                            new SqlParameter("@MenuID",obj.MenuID),
							new SqlParameter("@AdminRoleID",obj.AdminRoleID)
                                 };
            return DbHelper.ExecuteNonQuery(sql.ToString(), pra);
        }

        /// <summary>
        /// 删除
        /// </summary>
        public int Delete(Model.CNVP_AdminRoleMenu obj)
        {
           StringBuilder sql = new StringBuilder();
           sql.Append("delete from " + Prefix + "AdminRoleMenu where [AdminRoleID] = @AdminRoleID");
           SqlParameter[] pra = {
                                new SqlParameter("@AdminRoleID",obj.AdminRoleID)
						
                                };
           return DbHelper.ExecuteNonQuery(sql.ToString(),pra);
        }
        /// <summary>
        /// 查看单个
        /// </summary>
        public Model.CNVP_AdminRoleMenu LoadById(int ID)
        {
            
            StringBuilder sql = new StringBuilder();
            sql.Append("select [MenuID],[AdminRoleID] from " + Prefix + "AdminRoleMenu");
            sql.Append(" where [ID] = @ID");
            SqlParameter[] pra = {
                                 new SqlParameter("@ID",ID)
						
                                    };
            DataTable DT = DbHelper.ExecuteTable(sql.ToString(),pra);
            Model.CNVP_AdminRoleMenu cnvp_adminrolemenu = new Model.CNVP_AdminRoleMenu();
            if (DT != null && DT.Rows.Count > 0)
            {
                DataRow dr = DT.Rows[0];
                cnvp_adminrolemenu.MenuID = dr["MenuID"] is DBNull ? 0 : (int)dr["MenuID"];
                cnvp_adminrolemenu.AdminRoleID = dr["AdminRoleID"] is DBNull ? 0 : (int)dr["AdminRoleID"];
            }
             return cnvp_adminrolemenu;
        }
        /// <summary>
        /// 查看全部
        /// </summary>
        public List<Model.CNVP_AdminRoleMenu> LoadAll(string sqlWhere)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("select [ID],[MenuID],[AdminRoleID] from " + Prefix + "AdminRoleMenu");
            if (sqlWhere.Trim() != "")
            {
                sql.Append(" where " + sqlWhere);
            }
            DataTable DT = DbHelper.ExecuteTable(sql.ToString());
            List<Model.CNVP_AdminRoleMenu> list=new List<Model.CNVP_AdminRoleMenu>();
            if (DT != null && DT.Rows.Count > 0)
            {
                foreach (DataRow dr in DT.Rows)
                {
                    Model.CNVP_AdminRoleMenu cnvp_adminrolemenu = new Model.CNVP_AdminRoleMenu();
                    cnvp_adminrolemenu.ID = dr["ID"] is DBNull ? 0 : (int)dr["ID"];
                    cnvp_adminrolemenu.MenuID = dr["MenuID"] is DBNull ? 0 : (int)dr["MenuID"];
                    cnvp_adminrolemenu.AdminRoleID = dr["AdminRoleID"] is DBNull ? 0 : (int)dr["AdminRoleID"];
                    list.Add(cnvp_adminrolemenu);
                }
            }
            return list;

        }
        #endregion

        /// <summary>
        /// AdminRoleID,By MenuID
        /// </summary>
        public List<Model.CNVP_AdminRoleMenu> LoadAdminRoleIDByMenuID(int MenuID)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("select [AdminRoleID] from " + Prefix + "AdminRoleMenu");
            sql.Append(" where [MenuID] = @MenuID");
            SqlParameter[] pra = {
                                 new SqlParameter("@MenuID",MenuID)
						
                                    };
            DataTable DT = DbHelper.ExecuteTable(sql.ToString(),pra);
            List<Model.CNVP_AdminRoleMenu> list = new List<Model.CNVP_AdminRoleMenu>();
            if (DT != null && DT.Rows.Count > 0)
            {
                foreach (DataRow dr in DT.Rows)
                {
                    Model.CNVP_AdminRoleMenu cnvp_adminrolemenu = new Model.CNVP_AdminRoleMenu();
                    cnvp_adminrolemenu.AdminRoleID = dr["AdminRoleID"] is DBNull ? 0 : (int)dr["AdminRoleID"];
                    list.Add(cnvp_adminrolemenu);
                }
            }
            return list;

        }
    }
}

